# 首页面对象
import allure
from selenium.webdriver.common.by import By

from tshop.base.base import BasePage, BaseHandle


# 定义对象库层
class HomePage(BasePage):
    # 初始化
    def __init__(self):
        super().__init__()
        # 搜索输入框
        self.input_kw = By.CLASS_NAME, 'ecsc-search-input'
        # 搜索按钮
        self.input_btn = By.CLASS_NAME, 'ecsc-search-button'

    # 获取搜索输入框
    def find_input_kw(self):
        return self.get_element(self.input_kw)

    # 获取搜索按钮
    def find_input_btn(self):
        return self.get_element(self.input_btn)


# 定义操作层
class HomeHandle(BaseHandle):
    def __init__(self):
        super().__init__()
        self.home_page = HomePage()

    # 搜索输入操作
    @allure.step(title="输入搜索内容")
    def input_kw(self, text):
        self.input_text(self.home_page.find_input_kw(), text)

    # 搜索按钮操作
    @allure.step(title="点击搜索")
    def click_search_input_btn(self):
        self.home_page.find_input_btn().click()


# 定义业务层
class HomeProxy:
    def __init__(self):
        self.home_handle = HomeHandle()

    def search_goods(self, text):
        self.home_handle.input_kw(text)
        self.home_handle.click_search_input_btn()
